package com.hnucm.c202001020214.fragment;

import android.net.Uri;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.hnucm.c202001020214.GlideEngine;
import com.hnucm.c202001020214.R;
import com.luck.picture.lib.basic.PictureSelector;
import com.luck.picture.lib.config.SelectMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.interfaces.OnResultCallbackListener;

import java.io.File;
import java.util.ArrayList;


public class Sale extends Fragment {

    ImageView imageView3;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_sale, container, false);
        setView(view);

        return view;
    }
    public void setView(View view){


        imageView3 = view.findViewById(R.id.imageView3);
        imageView3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                //获取相册
                PictureSelector.create(Sale.this)
                        .openGallery(SelectMimeType.ofImage())
                        .setImageEngine(GlideEngine.createGlideEngine())
                        .forResult(new OnResultCallbackListener<LocalMedia>() {
                            @Override
                            public void onResult(ArrayList<LocalMedia> result) {

                                Glide.with(Sale.this)
                                        .load(Uri.fromFile(new File(result.get(0).getRealPath())))
                                        .into(imageView3);

                            }

                            @Override
                            public void onCancel() {

                            }
                        });

            }
        });

    }


}